<?php echo $this->render($this->includeDir . '/toolbar.php');?>
<?php echo $this->flashMessage();?>
<?php 
	$arrParam = $this->arrParam;
	/*===============================================
	 * Start - Tạo các phần tử cho Form
	 *===============================================*/	
	
	$name 		= $this->formText('name',Zendvn_Filter_Filter::filterContent($this->Item['name'],'filter'),array('class'=>'width-300 bg-green2 floatLeft' ));
	//$name 		.= $this->cmsError('name');
	
	$category_id = $this->cmsSelect('category_id',$this->Item['category_id'],
									array('size'=>10,'class'=>'width-150 bg-green2 floatLeft'),
									$this->slbParents);

	$picture	= $this->formFile('picture',array('class'=>'floatLeft'));
	if($this->arrParam['action'] == 'edit'){
		$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'news1Category.ini'));
	 	
	 	// Start - Lấy hình ảnh của avatar	 	
	 	$pictureConfig = $config->getConfig('item');
		
		$current_picture = '<div id="load-content-picture" class="clr width-150 center">';
		if(!empty($this->Item['picture'])){
			$pictureUrl = $pictureConfig['thumbUrl'] . '/' . $this->Item['picture'];
			$removeLink = $this->url(array('action'=>'remove-pic','type'=>'picture','file'=>$this->Item['picture']));
			$current_picture .= '<br>' . $this->cmsImage('picture',$pictureUrl,array('width'=>'75px'))
							. '<br><a  class="remove" href="javascript:loadPage(\'div#load-content-picture\',\'' . $removeLink . '\')">remove</a>';
		}
		
		$current_picture .= $this->formHidden('current_picture',$this->Item['picture'])
						. '</div>';
		$picture .=	$current_picture;		
	}
	$ordering	= $this->formText('ordering',$this->Item['ordering'],array('class'=>'width-100 floatLeft'));

	$options 	= array('inactive'=>$this->translate('Inactive'),'active'=>$this->translate('Active'));	
	$status 	= $this->formSelect('status',$this->Item['status'],array('class'=>'width-150'),$options);
	
	$strProcess		= new Zendvn_String();
	$description	= $strProcess->showText(Zendvn_Filter_Filter::filterContent($this->Item['description']));
	$description	= $this->tinyMce('description',$description,array('style'=>"width: 100%; height: 250px;"));
	$description  	= '<div id="d_description" style="width:98%; float: left">' . $description . '</div>';
	
	$map = $this->formTextarea('map',Zendvn_Filter_Filter::filterContent($this->Item['map']),array('class'=>'width-400','rows'=>8));
	$html_descript = $this->formTextarea('html_descript',Zendvn_Filter_Filter::filterContent($this->Item['html_descript'],'filter'),array('class'=>'width-400 floatLeft','rows'=>8));
	
	$html_keyword = $this->formTextarea('html_keyword',Zendvn_Filter_Filter::filterContent($this->Item['html_keyword'],'filter'),array('class'=>'width-400 floatLeft','rows'=>8));
	/*=======================================================
	 * Start - Tạo Tooltip cho các phần từ input trong form
	 *=======================================================*/	
	$formHelp = '';
	$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'news1Category.ini',
												'section'=>'tooltip'));
	$arrTooltip = $config->getConfig('item');
	if(count($arrTooltip)>0){
		foreach ($arrTooltip as $key => $val){
			$attribs = array();
			if($key=='d_description') $attribs = array('leftOffset'=>-305);
			$formHelp  .= $this->cmsFormHelp('.form-table #' . $key, $this->translate($val), $attribs);	
		}
	}
	
	/*=======================================================
	 * Start - Hiển thị các thông báo error của Form 
	 *=======================================================*/	
		
	 if(count($this->errors)>0){	
	 	foreach ($this->errors as $key => $val){	 		
	 		$$key .= $this->cmsError($key,$val);	
	 		$selector = '.form-table #' . $key . '-error';
	 		$options = array('type'=>'error','name'=>'#' .$key);
	 		$formHelp  .= $this->cmsFormHelp($selector, $this->translate($val),null,$options);
	 		
	 	}
	 }
	/*=======================================================
	 * end - Hiển thị các thông báo error của Form 
	 *=======================================================*/	
	
	 $arrRow = array(
						array('label'=>$this->translate('Name'),'input'=>$name),	
						array('label'=>$this->translate('Picture'),'input'=>$picture),									
						array('label'=>$this->translate('Category'),'input'=>$category_id),						
						array('label'=>$this->translate('Description'),'input'=>$description),						
						array('label'=>$this->translate('Map'),'input'=>$map),						
						array('label'=>$this->translate('Html descript'),'input'=>$html_descript),
						array('label'=>$this->translate('Html keywords'),'input'=>$html_keyword),
						array('label'=>$this->translate('Ordering'),'input'=>$ordering),
						array('label'=>$this->translate('Status'),'input'=>$status),
	
					 );
	$tdForm = $this->partialLoop('row.php',$arrRow);
	/*=======================================================
	 * Start - Hien thi chi tiet contact
	 *=======================================================*/	
	
	 $position		= $this->formText('position',Zendvn_Filter_Filter::filterContent($this->Item['position']),array('class'=>'width-200 floatLeft' ));
	 $email			= $this->formText('email',$this->Item['email'],array('class'=>'width-300 bg-green2 floatLeft' ));
	 $address		= $this->formTextarea('address',Zendvn_Filter_Filter::filterContent($this->Item['address']),array('class'=>'width-400 bg-green2 floatLeft','rows'=>8));
	 $city			= $this->formText('city',Zendvn_Filter_Filter::filterContent($this->Item['city']),array('class'=>'width-200 floatLeft' ));
	 $country		= $this->formText('country',Zendvn_Filter_Filter::filterContent($this->Item['country']),array('class'=>'width-200 floatLeft' ));
	 $telephone		= $this->formText('telephone',$this->Item['telephone'],array('class'=>'width-200 floatLeft' ));
	 $mobile		= $this->formText('mobile',$this->Item['mobile'],array('class'=>'width-200 floatLeft' ));
	 $fax			= $this->formText('fax',$this->Item['fax'],array('class'=>'width-200 floatLeft' ));
	 $website		= $this->formText('website',Zendvn_Filter_Filter::filterContent($this->Item['website']),array('class'=>'width-200 floatLeft' ));
	/*=======================================================
	 * Start - Tạo Tooltip cho các phần từ input trong form
	 *=======================================================*/	
	$formHelp = '';
	$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'news1Category.ini',
												'section'=>'tooltip'));
	$arrTooltip = $config->getConfig('item');
	if(count($arrTooltip)>0){
		foreach ($arrTooltip as $key => $val){
			$formHelp  .= $this->cmsFormHelp('.form-table #' . $key, $this->translate($val));	
		}
	}
	
	/*=======================================================
	 * Start - Hiển thị các thông báo error của Form 
	 *=======================================================*/	
		
	 if(count($this->errors)>0){	
	 	foreach ($this->errors as $key => $val){	 		
	 		$$key .= $this->cmsError($key,$val);	
	 		$selector = '.form-table #' . $key . '-error';
	 		$options = array('type'=>'error','name'=>'#' .$key);
	 		$formHelp  .= $this->cmsFormHelp($selector, $this->translate($val),null,$options);
	 		
	 	}
	 }
	/*=======================================================
	 * end - Hiển thị các thông báo error của Form 
	 *=======================================================*/	
	 $arrRow = array(
						array('label'=>$this->translate('Position'),'input'=>$position),	
						array('label'=>$this->translate('Email'),'input'=>$email),									
						array('label'=>$this->translate('Address'),'input'=>$address),									
						array('label'=>$this->translate('City'),'input'=>$city),									
						array('label'=>$this->translate('Country'),'input'=>$country),									
						array('label'=>$this->translate('Telephone'),'input'=>$telephone),									
						array('label'=>$this->translate('Mobile'),'input'=>$mobile),									
						array('label'=>$this->translate('Fax'),'input'=>$fax),									
						array('label'=>$this->translate('Website'),'input'=>$website),									
					
	
					 );
	$tdDetail = $this->partialLoop('row.php',$arrRow);
	/*=======================================================
	 * Start - Hien thi messeage 
	 *=======================================================*/	
	$messageError		= $strProcess->showText($this->Item['message_error']);
	$messageError		= $this->tinyMce('message_error',"<div id='test'>".$messageError."<div>",array('style'=>"width: 100%; height: 250px;"));
	
	$messageSuccess		= $strProcess->showText($this->Item['message_success']);
	$messageSuccess		= $this->tinyMce('message_success',"<div id='test'>".$messageSuccess."<div>",array('style'=>"width: 100%; height: 250px;"));
	
	 	 

	 $arrRow = array(
						array('label'=>$this->translate('Error Message'),'input'=>$messageError),	
						array('label'=>$this->translate('Success Message'),'input'=>$messageSuccess),									
					 );
	$tdMessage = $this->partialLoop('row.php',$arrRow);
	/*=======================================================
	 * Start - Hien thi cac cau hinh mac dinh cua Item
	 *=======================================================*/	
	$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'news1Category.ini',
												'section'=>'config'
											));
	
	$configPar 			= $config->getConfig('item');
	if($arrParam['action'] == 'edit'){
		$configPar 		= Zend_Json::decode($this->Item['params']);
	}
	$css				= array('class'=>'width-150');
	$options 			= array('show'=>$this->translate('Show'),'hide'=>$this->translate('Hidden'));	
	$cparamPicture		= $this->formSelect('cparam[picture]',$configPar['picture'],$css,$options);
	$cparamdescription	= $this->formSelect('cparam[description]',$configPar['description'],$css,$options);
	$cparamDescript		= $this->formSelect('cparam[descript]',$configPar['descript'],$css,$options);
	$cparamKeyword		= $this->formSelect('cparam[keyword]',$configPar['keyword'],$css,$options);
	$cparamMap			= $this->formSelect('cparam[position]',$configPar['position'],$css,$options);
	$cparamPosition		= $this->formSelect('cparam[map]',$configPar['map'],$css,$options);
	$cparamEmail		= $this->formSelect('cparam[email]',$configPar['email'],$css,$options);
	$cparamAddress		= $this->formSelect('cparam[address]',$configPar['address'],$css,$options);
	$cparamCity			= $this->formSelect('cparam[city]',$configPar['city'],$css,$options);
	$cparamCountry		= $this->formSelect('cparam[country]',$configPar['country'],$css,$options);
	$cparamTelephone	= $this->formSelect('cparam[telephone]',$configPar['telephone'],$css,$options);
	$cparamMobile		= $this->formSelect('cparam[mobile]',$configPar['mobile'],$css,$options);
	$cparamFax			= $this->formSelect('cparam[fax]',$configPar['fax'],$css,$options);
	$cparamWebsite		= $this->formSelect('cparam[website]',$configPar['website'],$css,$options);
	$cparamError		= $this->formSelect('cparam[error]',$configPar['error'],$css,$options);
	$cparamSuccess		= $this->formSelect('cparam[success]',$configPar['success'],$css,$options);
	

	$arrConfig = array(
						array('label'=>$this->translate('Picture'),'input'=>$cparamPicture),
						array('label'=>$this->translate('Description'),'input'=>$cparamdescription),
						array('label'=>$this->translate('HTML description'),'input'=>$cparamDescript),
						array('label'=>$this->translate('HTML keyword'),'input'=>$cparamKeyword),
						array('label'=>$this->translate('Map'),'input'=>$cparamMap),
						array('label'=>$this->translate('Position'),'input'=>$cparamPosition),
						array('label'=>$this->translate('Email'),'input'=>$cparamEmail),
						array('label'=>$this->translate('Address'),'input'=>$cparamAddress),
						array('label'=>$this->translate('City'),'input'=>$cparamCity),
						array('label'=>$this->translate('Country'),'input'=>$cparamCountry),
						array('label'=>$this->translate('Telephone'),'input'=>$cparamTelephone),
						array('label'=>$this->translate('Mobile'),'input'=>$cparamMobile),
						array('label'=>$this->translate('Website'),'input'=>$cparamWebsite),
						array('label'=>$this->translate('Error'),'input'=>$cparamError),
						array('label'=>$this->translate('Success'),'input'=>$cparamSuccess),
					 );
					 
	$tdConfig = $this->partialLoop('row.php',$arrConfig);
?>
<script type="text/javascript">
	$(document).ready(function() {
		<?php echo $formHelp;?>
	});
</script>
<div id="element-box">
	<div class="m">
		<div class="form-table">
        	<fieldset class="admin-fieldset">
                <legend class="admin-legend"><?php echo $this->translate('Form Detail')?></legend>
            	<table width="100%" border="0">
                	<?php echo $tdForm;?>
                </table>
                <div class="clr"></div>
        	</fieldset>  
        	 <fieldset class="admin-fieldset" style="margin-top:15px;">
                <legend class="admin-legend"><?php echo $this->translate('Contact Detail')?></legend>
                <table width="100%" border="0">
                	<?php echo $tdDetail;?>
                </table>
                <div class="clr"></div>
             </fieldset>           
        	 <fieldset class="admin-fieldset" style="margin-top:15px;">
                <legend class="admin-legend"><?php echo $this->translate('Contact Message')?></legend>
                <table width="100%" border="0">
                	<?php echo $tdMessage;?>
                </table>
                <div class="clr"></div>
             </fieldset>           
        	 <fieldset class="admin-fieldset" style="margin-top:15px;">
                <legend class="admin-legend"><?php echo $this->translate('Contact config')?></legend>
                <table width="100%" border="0">
                	<?php echo $tdConfig;?>
                </table>
                <div class="clr"></div>
             </fieldset>           
        </div>
       
        <div class="clr"></div>
	</div>
</div>
